export const GET_HOTSONGS = 'GET_HOTSONGS'
export const GET_HOTSONGS_SUCCESS = 'GET_HOTSONGS_SUCCESS'
export const GET_HOTSONGS_FAILED = 'GET_HOTSONGS_FAILED'

export interface IGetHotSongsAction {
  type: typeof GET_HOTSONGS
}

export interface IAuthor {
  id: number,
  name: string
}

export interface IHotSong {
  al: {
    id: number,
    name: string,
    pic: number,
    picUrl: string,
    pic_str: string
  },
  ar: IAuthor[],
  id: number,
  name: string
}

export interface IPlaylistResult {
  tracks: IHotSong[]
  updateTime: number
}

export interface IGetHotSongsResult {
  code: number,
  playlist: IPlaylistResult
}

export interface IGetHotSongsSuccessAction {
  type: typeof GET_HOTSONGS_SUCCESS,
  payload: IGetHotSongsResult
}

export interface IGetHotSongsFailedAction {
  type: typeof GET_HOTSONGS_FAILED,
  payload: string
}

export const getHotSongs = (): IGetHotSongsAction => {
  return {
    type: GET_HOTSONGS
  }
}

export const getHotSongsSuccess = (payload: IGetHotSongsResult): IGetHotSongsSuccessAction => {
  return {
    type: GET_HOTSONGS_SUCCESS,
    payload
  }
}

export const getHotSongsFailed = (errorMessage: string): IGetHotSongsFailedAction => {
  return {
    type: GET_HOTSONGS_FAILED,
    payload: errorMessage
  }
}

export type HotSongsUnionActionType = IGetHotSongsAction | IGetHotSongsSuccessAction | IGetHotSongsFailedAction